module WeekSelect

  # Returns a select tag with options for selecting weeks, pre-selected with the +time+.
  def week_select(time = Time.now, options = {:week_range => 3})
    week_options = []

    1.upto(options[:week_range]) do |week_number|
      start_of_week = (time + week_number.weeks).beginning_of_week
      selected_html = start_of_week == Time.now.beginning_of_week ? "selected='selected'" : ""
      week_options << %(<option value="#{start_of_week.to_s}" #{selected_html}>#{start_of_week.strftime("%A %d %B %Y")}</option>\n)
    end
    
    select_html(options[:field_name] || 'week', week_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled])
  end

end